package cn.itsource.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: hong
 * @Description:
 * @Date:
 * @Modified: By:
 */
@Configuration
public class CustomParamResolverConfigurer implements WebMvcConfigurer {
//    @Autowired
//    LoginCheckInterceptor loginCheckInterceptor;

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>> ();
        converters.add(new MappingJackson2HttpMessageConverter());
        resolvers.add(new CustomMethodArgumentResolver());
        //resolvers.add (new MyRequestResponseBodyMethodProcessor (converters));
        WebMvcConfigurer.super.addArgumentResolvers(resolvers);

    }

    /**
     * 这里就是注入拦截器的地方
     * @param registry
     */
//    public void addInterceptors(InterceptorRegistry registry) {
////        registry.addInterceptor(loginCheckInterceptor)
////                //这里是放行路径
////                .excludePathPatterns("/**/login","/file/upload","/shop/register",
////                        "/user/sendmobilecode/**","/user/checkphone/**","/user")
////                //这里是放行swagger的路径
////                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**")
////                //这个方法是拦截路径
////                .addPathPatterns("/**");
////    }

//    @Autowired
//    private LoginCheckInterceptor loginCheckInterceptor;

//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        //将自定义的拦截器，添加到Springmvc的配置中，这样就可以生效
//        registry.addInterceptor(loginCheckInterceptor).addPathPatterns("/**")
//                .excludePathPatterns(
//                        "/user/login",
//                        "/file/upload",
//                        "/shop/register",
//                        "/user/sendmobilecode/**",
//                        "/user/checkphone/**",
//                        "/user/**",
//                        "/empl/login",
//                         "/swagger-resources/**",
//                        "/webjars/**",
//                        "/v2/**",
//                        "/swagger-ui.html/**",
//                        "**/access/**",
//                        "/baidu/**",
//                        "/pet/type/findAll"
//                );
//
//    }


//    @Bean
//    public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
//        RequestMappingHandlerAdapter requestMappingHandlerAdapter = super.requestMappingHandlerAdapter();
//        List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
//        converters.add(new DataMessageConvert());
//        List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<HandlerMethodArgumentResolver> ();
//        argumentResolvers.add(new MyResolver(converters));
//        requestMappingHandlerAdapter.setCustomArgumentResolvers(argumentResolvers);
//        List<HandlerMethodReturnValueHandler> returnValueHandlers = new ArrayList<HandlerMethodReturnValueHandler>();
//        returnValueHandlers.add(new MyResolver(converters));
//        requestMappingHandlerAdapter.setCustomReturnValueHandlers(returnValueHandlers);
//        return requestMappingHandlerAdapter;
//    }
}


